package com.example.bookrecommendationjava.controller;

import com.example.bookrecommendationjava.mapper.BookMapper;
import com.example.bookrecommendationjava.mapper.LikeMapper;
import com.example.bookrecommendationjava.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @BelongsProject: book-recommendation-java
 * @BelongsPackage: com.example.bookrecommendationjava.controller
 * @Author: ZhShy
 * @CreateTime: 2022-03-17 19:51
 * @Description:
 */
@Controller
@RequestMapping("like")
@CrossOrigin(origins = "*", maxAge = 3600)
public class LikeController {
    @Autowired
    BookMapper bookMapper;
    @Autowired
    UserMapper userMapper;
    @Autowired
    LikeMapper likeMapper;

    @RequestMapping("like")
    @ResponseBody
    public void insertLike(@RequestParam Integer userId, @RequestParam Integer bookId) {
        likeMapper.insertIntoLike(userId, bookId);
    }

    @RequestMapping("noLike")
    @ResponseBody
    public void deleteLike(@RequestParam Integer userId, @RequestParam Integer bookId) {
        likeMapper.deleteFromLikeByUserIdAndBookId(userId, bookId);
    }

}
